﻿using IOA.MES.Business;
using IOA.MES.DataAccess.Enum;
using IOA.MES.DataAccess.VModel;
using IOA.MES.PdaApi.Models.Request.Downgrade;
using IOA.MES.PdaApi.Models.Response.Downgrade;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace IOA.MES.PdaApi.Controllers
{
    /// <summary>
    /// 降级复判
    /// </summary>
    public class DowngradeController : ApiController
    {
        /// <summary>
        /// 降级组件
        /// </summary>
        [HttpPost]
        public ResultJson<DowngradeResponse> Downgrade([FromBody] DowngradeRequest request)
        {
            new DowngradeMgr().Downgrade(new List<string> { request.BarCode }, new List<string> { request.DowngradeDesc }, request.CurSite, request.Level, BaseEnv.User.PkId);
            return new ResultJson<DowngradeResponse>();
        }

        ///// <summary>
        ///// 复判组件
        ///// </summary>
        //[HttpPost]
        //public ResultJson<ReviewResponse> Review([FromBody] ReviewRequest request)
        //{
        //    var user = BaseEnv.User;
        //    new DowngradeMgr().Review(new VDowngrade
        //    {
        //        BarCode = request.BarCode.Trim('\n'),
        //        ReviewedBy = user.PkId,
        //        //ReviewResult = request.ReviewResult,
        //        ReviewDesc = request.ReviewDesc,
        //        ModifyBy = user.PkId
        //    });
        //    return new ResultJson<ReviewResponse>();
        //}

        /// <summary>
        /// 查询等级列表
        /// </summary>
        [HttpPost]
        public ResultJson<QueryLevelsResponse> QueryLevels([FromBody] QueryLevelsRequest request)
        {
            var levels = new LevelColorMgr().QueryLevels();
            return new ResultJson<QueryLevelsResponse>(new QueryLevelsResponse
            {
                Levels = levels.Select(_ => _.Level).ToList()
            });
        }

        /// <summary>
        /// 降级组件
        /// </summary>
        [HttpPost]
        public ResultJson<QueryReviewTypesResponse> QueryReviewTypes([FromBody] QueryReviewTypesRequest request)
        {
            var types = new CommonMgr().QueryEnumTypes(typeof(ReviewResult));
            return new ResultJson<QueryReviewTypesResponse>(new QueryReviewTypesResponse { ReviewTypes = types });
        }

        /// <summary>
        /// 查询降级列表
        /// </summary>
        //[HttpPost]
        //public ResultJson<QueryResponse> Query([FromBody] QueryRequest request)
        //{
        //    var total = 0;
        //    var models = new DowngradeMgr().QueryDowngrades(request.PageIndex, request.PageSize, out total, request.WorkshopCode, "", "", "", null, null, request.Reviewed, null);
        //    return new ResultJson<QueryResponse>(new QueryResponse
        //    {
        //        Downgrades = models.Select(_ => new Downgrade
        //        {
        //            DowngradeId = _.PkId,
        //            BarCode = _.BarCode,
        //            DowngradeType = _.DowngradeType,
        //            CNCreateBy = _.CNCreateBy,
        //            CNReviewedBy = _.CNReviewedBy,
        //            CNReviewResult = _.CNReviewResult,
        //            DowngradeDesc = _.DowngradeDesc,
        //            OrderNo = _.OrderNo,
        //            ProductCode = _.ProductCode,
        //            ProductName = _.ProductName,
        //            ReviewDesc = _.ReviewDesc,
        //            Reviewed = _.Reviewed,
        //            ReviewResult = _.ReviewResult,
        //            ReviewTime = _.ReviewTime,
        //            CurSiteName = _.CurSiteName,
        //            LockSiteName = _.LockSiteName,
        //            WorkOrderNo = _.WorkOrderNo,
        //            WorkshopCode = _.WorkshopCode,
        //            WorkshopName = _.WorkshopName,
        //            CreateTime = _.CreateTime
        //        }).ToList()
        //    });
        //}

        /// <summary>
        /// 获取降级详情
        /// </summary>
        //[HttpPost]
        //public ResultJson<GetDetailResponse> GetDetail([FromBody] GetDetailRequest request)
        //{
        //    var model = new DowngradeMgr().GetDowngrade(request.DowngradeId);

        //    return new ResultJson<GetDetailResponse>(new GetDetailResponse
        //    {
        //        Downgrade = model == null ? null : new Downgrade
        //        {
        //            DowngradeId = model.PkId,
        //            BarCode = model.BarCode,
        //            DowngradeType = model.DowngradeType,
        //            CNCreateBy = model.CNCreateBy,
        //            CNReviewedBy = model.CNReviewedBy,
        //            CNReviewResult = model.CNReviewResult,
        //            DowngradeDesc = model.DowngradeDesc,
        //            OrderNo = model.OrderNo,
        //            ProductCode = model.ProductCode,
        //            ProductName = model.ProductName,
        //            ReviewDesc = model.ReviewDesc,
        //            Reviewed = model.Reviewed,
        //            ReviewResult = model.ReviewResult,
        //            ReviewTime = model.ReviewTime,
        //            CurSiteName = model.CurSiteName,
        //            LockSiteName = model.LockSiteName,
        //            WorkOrderNo = model.WorkOrderNo,
        //            WorkshopCode = model.WorkshopCode,
        //            WorkshopName = model.WorkshopName,
        //            CreateTime = model.CreateTime
        //        }
        //    });
        //}
    }
}
